<!--************************************************************************************************-->
<!-- < GroupManager.php >                                                                           -->
<!-- Copyright (c) 2012-2013 San Yat-sun University School of Software                              -->
<!-- Founder : Tianjiao Li                                                                          -->
<!-- Stu : 10389129                                                                                 -->
<!-- Date: 2012-12-18                                                                               -->
<!-- Destription : Add                                                        -->
<!-- Basic: User:root                                                                               -->
<!--	    Password:                                                                               -->
<!-- Version : 2.1                                                                                  -->
<!-- LastUpdate : 2012-12-23 16:00 BY Tianjiaoli                                                    -->
<!--************************************************************************************************-->

<?php 
	include_once("../db/Comment.php");
	class CommentManager
	{
		static $instance;
		private $comment;
		
		public function __construct(){
		}
		
		public static function getInstance(){
			if (self::$instance == null)
				self::$instance = new self();
			return self::$instance;
		}
		
		public function insert($array)
		{
			$comment = new Comment($array);
			$comment->insert();
			return true;
		}
		
		public function delete($array)
		{
			$comment = new Comment($array);
			$comment->delete();
		}
		
		public function update($array)
		{
			$comment = new Comment($array);
			$comment->update();
		}
		
		public function getAllValue()
		{
			$comment = new Comment(null);
			return $comment->findAllValue();
		}
		
		public function getValueByUsername($Username)
		{
			$comment = new Comment(null);
			return $comment->findValueByUsername($Username);
		}
		
		public function getValueByBookname($bookname)
		{
			$comment = new Comment(null);
			return $comment->findValueByBookname($bookname);	
		}
		
		public function getValueByThesisname($Thesisname)
		{
			$comment = new Comment(null);
			return $comment->findValueByThesisname($Thesisname);
		}
		
		public function getCommentlistByUsername($Username, $N)
		{
			$comment = new Comment(null);
			
			if ($N == null)
				$comment_list = $comment->findCommentlistByUsername($Username);
			else
				$comment_list = $comment->findNCommentsByUsername($Username, $N);
			
			$comment_contents = $this->getCommentcontents($comment_list);
			
			return $comment_contents;
		}
		
		public function getCommentcontents($comment_list)
		{
			$comment_contents = array();
			while($row = mysql_fetch_array($comment_list))
				$comment_contents[] = $row['Content']; 
			return $comment_contents;
		}
	}
?>